package com.yang.dao;

import com.yang.entity.UserThings;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 用户事件表(UserThings)表数据库访问层
 *
 * @author yangdacheng
 * @since 2022-03-02 19:11:03
 */
@Mapper
@Repository
public interface UserThingsDao {
//    <result property="userThingsId" column="userThingsID" jdbcType="VARCHAR"/>
//        <result property="userid" column="userID" jdbcType="VARCHAR"/>
//        <result property="thingsId" column="thingsID" jdbcType="VARCHAR"/>

    /**
     * 添加新的用户事件
     * @param userThings
     * @return
     */
    @Insert("INSERT INTO userThings VALUES(#{userThingsId},#{userid},#{thingsId})")
    Boolean insertUserThings(UserThings userThings);

    /**
     * 根据事件编号删除事件
     * @param thingsID
     * @return
     */
    @Delete("DELETE FROM userThings WHERE thingsID = #{thingsID}")
    Boolean deleteUserThings(String thingsID);

    /**
     * 根据用户编号获取用户事件
     * @param uid
     * @return
     */
    @Results(value = {
            @Result(column = "userThingsID",property = "userThingsId",id = true),
            @Result(column = "userID",property = "userid"),
            @Result(column = "thingsID",property = "thingsId"),
            @Result(column = "thingsID",property = "noteThings",one = @One(
                    select = "com.yang.dao.NoteThingsDao.queryThingsByID"
            ))
    },id = "userThingsMapper")
    @Select("SELECT * FROM userThings WHERE userID = #{uid}")
    List<UserThings> queryThingsByUID(String uid);

    /**
     * 根据事件编号获取用户事件信息
     * @param tid
     * @return
     */
    @ResultMap("userThingsMapper")
    @Select("SELECT * FROM userThings WHERE thingsID = #{tid}")
    UserThings queryThingsByTID(String tid);
}